// preload.js
import { contextBridge, ipcRenderer } from 'electron'

const originalXMLHttpRequest = XMLHttpRequest;

class ProxyXMLHttpRequest extends originalXMLHttpRequest {
  constructor() {
    super();
    this.addEventListener('readystatechange', () => {
      if (this.readyState === 4) {
        ipcRenderer.send('ajax-request-completed', this.response);
      }
    });
  }

  open(method, url, async, user, pass) {
    super.open(method, url, async, user, pass);
  }

  send(data) {
    super.send(data);
  }

  test(){
    console.log('test')
  }
}

window.XMLHttpRequest = ProxyXMLHttpRequest;